<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-row :gutter="24">
        <div class="jjwjsj-title">
          <span>基本情况表</span>
        </div>
        <a-col :offset="16" :md="8" :sm="8" style="display: flex; justify-content: flex-end; align-items: center">
          <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
            <a-button :disabled="editingKey !== ''" type="primary" icon="search" @click="searchQuery">查询</a-button>
            <a-button
              :disabled="editingKey !== ''"
              type="primary"
              icon="download"
              @click="OnExportList"
              style="margin: 0px 8px"
            >
              导出
            </a-button>
            <a-upload
              name="file"
              :showUploadList="false"
              :multiple="false"
              :headers="tokenHeader"
              :before-upload="beforeUpload"
              :action="importExcelUrl"
              @change="handleImportExcel"
              accept=".docx, .doc, .xlsx, .xls, .pdf, .jpeg, .png"
            >
              <a-button :loading="upLoading" :disabled="editingKey !== '' || upLoading" type="primary" icon="import">导入</a-button>
            </a-upload>
            <a-button
              v-if="OrgLevel != '1'"
              :disabled="!(reportSelectIds.length > 0 && editingKey == '')"
              type="primary"
              @click="SubmitDataId(1)"
              style="margin: 0px 8px"
            >
              一键提交</a-button
            >
          </span>
        </a-col>
      </a-row>
    </div>

    <!-- 列表区域 -->
    <div>
      <div class="inforMation">
        <span >
          
        </span>
        <span>单位：项</span>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        class="edit-list"
        rowKey="id"
        :row-selection="rowSelection"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
        :scroll="{ x: 2500, y: 350 }"
      >
        <span slot="endTimeTitleA">2022年久竣未结项目治理目标</span>
        <span slot="endTimeTitleB">2022年治理目标完成情况</span>

        <template v-for="col in targetColList" :slot="col" slot-scope="text, record, index">
          <div :key="col">
            <a-input-number
              v-if="record.editable"
              :value="text"
              style="width: 100%"
              @change="(value) => handleChange(value, record.id, col)"
            />
            <template v-else>
              {{ text }}
            </template>
          </div>
        </template>

        <template v-slot:action="text, record">
          <div v-if="record.totalName !== '合计' && !record.serialnumber" class="editable-row-operations">
            <span v-if="record.editable">
              <a @click="() => save(record.id)">保存</a>
              <a-divider type="vertical" />
              <a-popconfirm title="是否舍弃本次编辑内容？" @confirm="() => cancel(record.id)">
                <a>取消</a>
              </a-popconfirm>
            </span>
            <span v-else>
              <a :disabled="editingKey !== ''" @click="() => edit(record.id)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm
                :disabled="editingKey !== ''"
                title="是否确认删除？"
                @confirm="
                  () => {
                    Delete(record)
                  }
                "
              >
                <a>删除</a>
              </a-popconfirm>
            </span>
          </div>
        </template>
      </a-table>
      <div class="table-pagination" v-if="total > 0">
        <a-pagination
          v-bind="ipagination"
          :total="total"
          @showSizeChange="onShowSizeChange"
          @change="handleTableChange"
        />
      </div>
    </div>
  </a-card>
</template>

<script>
import { filterObj } from '@/utils/util'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { CommonMixin } from '@/views/sj/sjxxzhbb/jjwjsj/mixins/common.js'
import columns from './indexColumns'
import { deleteAction, getAction, downFile, getFileAccessHttpUrl, httpAction, postAction } from '@/api/manage'
export default {
  mixins: [JeecgListMixin, CommonMixin],
  data() {
    return {
      columns: columns(this),
      importExcelUrl: `${window._CONFIG['domianURL']}/sjxxzhbb/jbqkb/importExcel`,
      url: {
        list: '/sjxxzhbb/jbqkb/list',
        hjlist: '/sjxxzhbb/jbqkb/dataSum',
        exportList: '/sjxxzhbb/jbqkb/exportXls',
        isExistenceExcel: '/sjxxzhbb/jbqkb/isCurDeptImport',
        saveRowData: '/sjxxzhbb/jbqkb/isCurDeptImport',
        delete: '/sjxxzhbb/jbqkb/deleteById',
        saveRowData: '/sjxxzhbb/jbqkb/edit',
      },
      editingKey: '',
      targetColList: [
        'dwmc',
        'zxzlJjwjZs',
        'zxzlJjwjLn',
        'zxzlJjwjLw',
        'zxzlYjwjZs',
        'zxzlYjwjLn',
        'zxzlYjwjLw',
        'zxzlZlmbXjzs',
        'zxzlZlmbLn',
        'zxzlZlmbLw',
        'dchsqkJjwjZs',
        'dchsqkJjwjLn',
        'dchsqkJjwjLw',
        'dchsqkJjwjJw',
        'dchsqkYjwjZs',
        'dchsqkYjwjLn',
        'dchsqkYjwjLw',
        'dchsqkYjwjJw',
        'dchsqkYjyjZs',
        'dchsqkYjyjLn',
        'dchsqkYjyjLw',
        'dchsqkYjyjJw',
        'dchsqkWckqXjzs',
        'dchsqkWckqLn',
        'dchsqkWckqLw',
        'dchsqkWckqJw',
      ],
      // ipagination: {
      //   current: 1,
      //   pageSize: 10,
      //   pageSizeOptions: ['10', '20', '30'],
      //   showTotal: (total, range) => {
      //     return range[0] + '-' + range[1] + ' 共' + total + '条'
      //   },
      //   showQuickJumper: true,
      //   showSizeChanger: true,
      //   total: 0,
      // },
    }
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() // 查询条件
      this.loading = true
      // this.dataSource=[]
      return getAction(this.url.list, params).then((res) => {
        if (res.success) {
          // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          if (this.TotalData.length > 0) {
            this.dataSource = [].concat(this.TotalData[0], res.result.records || res.result)
          } else this.dataSource = res.result.records || res.result || []
          this.cacheData = _.cloneDeep(this.dataSource)
          if (res.result.total) {
            this.total = res.result.total
          } else {
            this.total = 0
          }
          // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        } else {
          this.$message.warning(res.message)
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    getQueryParams() {
      // 获取查询条件
      const sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      if (this.superParam) {
        var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters, this.superParam)
      } else {
        var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters)
      }
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      return filterObj(param)
    },
    save(id) {
      let NewData = [...this.dataSource]
      let targetRowData = NewData.find((item) => id === item.id)
      if (targetRowData) {
        this.editingKey = ''
        delete targetRowData.editable
        this.SaveEditRowData(targetRowData)
      } else {
        this.$message.error('出现计算错误,联系开发人员')
      }
    },
  },
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '~@views/sj/sjxxzhbb/css/baobiaotable.less';
.table-pagination {
  margin: 16px 0px;
  display: flex;
  justify-content: end;
}
</style>